// src/mixins/scrollMixin.js
export default {
  data() {
    return {
      scrollY: 0
    };
  },
  methods: {
    // 滚动回调（目前未用）
    handleScroll() {
      this.scrollY = window.scrollY || window.pageYOffset;
    },

    mainLeftChange() {
      const mainLeftT = 20;

      const innerLeft = document.querySelector('.inner_left');
      const mainLeft = document.querySelector('.main1 .left');
      const mainRight = document.querySelector('.main1 .right');
      if (!innerLeft || !mainLeft || !mainRight) return;
      const getOffsetTop = (el) => {
        let offsetTop = 0;
        while (el) {
          offsetTop += el.offsetTop;
          el = el.offsetParent;
        }
        return offsetTop;
      };

      const mainLeftTop = getOffsetTop(innerLeft);
      const winH = window.innerHeight;
      const mainLeftH = mainLeft.offsetHeight;
      const mainRightT = getOffsetTop(mainRight);
      const winTop = window.pageYOffset || document.documentElement.scrollTop;
      const mainRightH = mainRight.offsetHeight;
  

      
      // if (winH > mainLeftH) {
        // 添加或移除吸顶类
  
        if (winTop >= mainLeftTop - mainLeftT) {
          innerLeft.classList.add('off');
        } else {
          innerLeft.classList.remove('off');
        }

        const leftToBottom = winH - mainLeftH - mainLeftT;
        const rightToBottom = winH - (mainRightH + mainRightT - winTop);

        if (leftToBottom <= rightToBottom) {
          innerLeft.classList.add('off_ab');
        } else {
          innerLeft.classList.remove('off_ab');
        }
      // }
    }
  },
  mounted() {
    window.addEventListener('scroll', this.mainLeftChange);
    console.log('scrollMixin 混入 mounted');
    this.mainLeftChange(); // 初始化判断

  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.mainLeftChange);
  }
};
